package com.zhuoyue.biz.core.command.cmd.common.faa;

import com.zhuoyue.biz.core.api.domain.DeviceAndGatewayDO;
import com.zhuoyue.biz.core.api.dto.req.ControlReq;
import com.zhuoyue.biz.core.command.cmd.common.faa.base.SetCmd;
import com.zhuoyue.common.constant.DataBase;

import java.util.List;

import static com.zhuoyue.common.constant.ControlType.Set.SCENE_SET_REQUEST;


/**
 * 液晶场景面板
 *
 * @author Administrator
 */
public class LcdSceneController0Faa8A03 extends SetCmd {
    private static Integer setRoad = null;

    /**
     * 场景配置
     *
     * @param deviceAndGatewayDO
     * @param controlReq         actions:{
     *                           sceneId:xxxxxxx
     *                           setRoad:1
     *                           }
     *                           controlType:"SCENE_SET_REQUEST"
     */
    public static String set(DeviceAndGatewayDO deviceAndGatewayDO, ControlReq controlReq, List<String> sceneMessage) {
        setRoad = (Integer) controlReq.getActions().get("setRoad");
        String cmd = "";
        switch (controlReq.getControlType()) {
            case SCENE_SET_REQUEST:
                //场景配置
                cmd = getControlCmd(deviceAndGatewayDO, sceneSet(sceneMessage));
                break;
            default:
                break;
        }
        return cmd;
    }

    private static String sceneSet(List<String> sceneMessage) {
        int scene32 = 32;
        String nameLength = "0" + (sceneMessage.get(1).length() / 2) + "";
        String nameStr = sceneMessage.get(1);
        for (int i = 0; i < sceneMessage.get(1).length() - scene32; i++) {
            nameStr = nameStr + 0;
        }
        return setRoad < 10 ? "0" + setRoad : setRoad + "" + DataBase.DATA_LENGTH_12 + sceneMessage.get(0) + nameLength + nameStr;
    }
}
